from selenium.webdriver.common.keys import Keys

from public.tools import *
from public.action import *
from public.testDATE import *
"""
1.在首页搜索"小米",点击搜索按钮
2.选择小米mix3,加入到购物车,点击购物车按钮
3.点击"去结算"按钮
4.默认地址已经选择,点击下一步按钮
5.支付方式选择"余额支付",点击确认订单
6.点击"查看订单详情",点击"取消订单"
"""
testCase="DBshop004_购物取消订单"
SP="小米"

firefox =openB(url)
login(firefox,user,password)
#搜索小米
firefox.find_element_by_xpath("//input[1]").send_keys(SP)
firefox.find_element_by_xpath("//input[@class='search-btn iconfont']").click()
#加入购物车
firefox.find_element_by_xpath("//img[@alt='小米Mix3 全网通版 8GB+128GB 黑色 磁动力滑盖全面屏']").click()
chage(firefox,2)
time.sleep(1)
firefox.find_element_by_id("add_cart_submit").click()
firefox.find_element_by_link_text("去购物车结算").click()
firefox.find_element_by_link_text("去结算").click()
#去结算下一步
firefox.find_element_by_xpath("//input[@value='下一步']").click()
#选择余额支付
firefox.find_element_by_xpath("//input[@value='yezf']").click()
firefox.find_element_by_xpath("//input[@value='确认订单']").click()
#保存订单号
orderID=firefox.find_element_by_xpath("(//font[@color='color:#ED145B'])[2]").text
print(orderID)
rootpath=get_pro_rootpath()
writeFile(rootpath+r"\public\QXdh.txt",orderID)

#点击"查看订单详情",点击"取消订单"
firefox.find_element_by_xpath("//input[@value='查看订单详情']").click()
firefox.find_element_by_xpath("//div/button[2]").click()
firefox.switch_to.alert.accept()
firefox.find_element_by_partial_link_text("无效订单").click()
firefox.find_element_by_xpath("//input[@name='search_order_sn']").send_keys(danhao)
firefox.find_element_by_xpath("//button").click()

#断言
try:
    firefox.find_element_by_link_text(orderID).is_displayed()  #is_displayed()函数判断元素是否显示
    writeLog("%s 测试通过"%testCase)
except:
    writeLog("%s 测试失败" % testCase)
    getPhoto(firefox)
firefox.quit()
#